<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title>个人资料</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="css/common.css"/>
		<link rel="stylesheet" type="text/css" href="css/index.css"/>
	</head>
	<body class="bg_ff">
		<header class="mui-bar mui-bar-nav">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title">个人资料</h1>
		</header>
		<div class="mui-content bg_ff">
		    <div class="text-center">
		    	<label for="file"><img class="logo " src="images/headimg.png"/></label>
			    <input type="file" name="" hidden="hidden" id="file" value="" />
		</div>
		
		<div class="form">
			<div class="input_list">
				<input type="text" name="" id="name" value="" placeholder="用户昵称"/>
			</div>
			<div class="input_list">
				<input type="text" name="" id="labels" value="" placeholder="个性签名"/>
			</div>
			
			
			<p class="text-center mg_top20"><a href="javascript:void(0);" class="big_btn" onclick="updata()">保存</a></p>
		</div>
		</div>
		
		
		<script src="js/mui.js"></script>
		<script src="js/jquery-1.7.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/index.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			mui.init()
			
			function getUserInfoById(){
				$('.gif').show()
				$.ajax({
					type:"post",
					url:urlcom + "user/getUserInfoById",
					async:true,
					dataType:'json',
					data:{
						userId:localStorage.getItem('userId')
					},
					success:function(res){
						$('.gif').hide()
						if(res.code==0){
							$('#name').val(res.data.name)//用户名
							$('.logo').attr('src',res.data.headImg)//头像
							$('#labels').val(res.data.labels)//自我签名
						
						}else{
							msg(res.msg)
						}
					}
			     })
			}getUserInfoById()
			//formdata 上传图片
		    $("#file").change(function(){
					$('.gif').show()
				var formData = new FormData();
				var fils=document.getElementById('file').files[0]
				console.log(fils)
				formData.append('file',fils);
				
				formData.append('userId',localStorage.getItem('userId'));
				$.ajax({
					type:'post',
					url:urlcom+'upload/image',
					data:formData,
					dataType:'json',
					contentType:false,
					processData:false,
					success:function(res){
							$('.gif').hide()
						console.log(res)
						$('.logo').attr('src',res.data.pictureName);
//						
					},
					error:function(){
					}
			    })
				
			})
//		    function upimg(){
//		    	var head_img = $('.logo').attr('src')
//		    	$.ajax({
//					type:'post',
//					url:urlcom+'/upload/image',
//					dataType:'json',
//					data:{
//						token:localStorage.getItem('user_token'),
//						picture:head_img
//					},
//					success:function(res){
//						msg(res.msg)
//						
//					},
//					error:function(){
//					}
//			    })
//		    }
		   
			
			
			function updata(){
				$.ajax({
					type:"post",
					url:urlcom + "user/updateUserInfo",
					async:true,
					dataType:'json',
					data:{
						userId:localStorage.getItem('userId'),
						name:$('#name').val(),
						labels:$('#labels').val(),
						headImg:$('.logo').attr('src')
					},
					success:function(res){
						if(res.code==0){
							msg('修改成功')
							setTimeout(function(){
								window.location.href = 'my.html'
							},1000)
							
						}else{
							msg(res.msg)
						}
		 			}
			     })
			}
		</script>
	</body>

</html>
